export class GeneratorExecutor {
    constructor() {
        this.reset = false;
    }

    static run(gen, callback) {
        let g = gen;
        let _this = this;
        this.reset = false;

        function next() {
            let result = g.next();
            if (result.done) {
                callback();
                return result.value;
            }
            if (!_this.reset) {
                result.value.then(function () {
                    next();
                }).catch(function (error) {
                    console.log(error);
                    //异常的话，继续向下执行
                    next();
                });
            }
        }
        next();
    }

    static pause() {
        this.reset = true;
    }
}
